package com.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.IFolderDao;
import com.ssm.domain.Folder;
import com.ssm.domain.SysFile;
import com.ssm.service.IFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文件夹业务接口实现
 */
@Service
public class FolderServiceImpl implements IFolderService {

    @Autowired
    private IFolderDao folderDao;

    @Override
    public List<Folder> findAll(Integer page, Integer size) throws Exception {
        PageHelper.startPage(page,size);
        return folderDao.findAll();
    }

    @Override
    public void save(Folder folder) throws Exception {
        folderDao.save(folder);
    }

    @Override
    public void deleteFolder(String folderId) throws Exception {
        folderDao.deleteFolderfromFile(folderId);
        folderDao.deleteFolder(folderId);
    }

    @Override
    public Folder findById(String folderId) throws Exception {
        return folderDao.findById(folderId);
    }

    @Override
    public List<SysFile> findOtherFiles(String folderId) throws Exception {
        return folderDao.findOtherFiles(folderId);
    }

    @Override
    public void addFileToFolder(String folderId, String[] fileIds) throws Exception {
        for(String fileId:fileIds) {
            folderDao.addFileToFolder(folderId, fileId);
        }

    }
}
